<?php
namespace App\Logic\Layui\Service;

use app\Logic\Layui\ServiceProviders\Loger;
use app\Logic\Logic;
use Illuminate\Support\Facades\DB;

class BusinessLog extends Logic implements ServiceInterface
{
    public $app;

    private $table;

    public function __construct(Loger $app)
    {
        $this->app = $app;

        $this->table = DB::connection('xz')->table('zk_error_log');
    }

    public function lists()
    {
        $request = request();
        $data = $request->input();
        $condition = [];
        if(isset($data['action'])) $condition[] = ['action','like',"%{$data['action']}%"];
        if(isset($data['content'])) $condition[] = ['content','like',"%{$data['content']}%"];
        if(isset($data['session_id'])) $condition[] = ['session_id','=' ,$data['session_id']];
        $start = start($data['page'], $data['limit']);
        $count = $this->table->where($condition)->count();
        $res = $this->table->where($condition)->offset($start)->limit($data['limit'])->orderBy('created_at', 'desc')->get();
        /*$sql = "SELECT xz_session_id,xz_uid FROM zk_member_login where 1 GROUP BY id ORDER BY addTime DESC";
        $res = DB::connection('xz')->select($sql);var_dump($res);die;*/
        /*$res = DB::connection('xz')->select("
        SELECT
	      log.*, zk_users.phoneNumber
        FROM
	    (
            SELECT
                el.*, ml.xz_uid
            FROM
                zk_error_log el,
                (
                    SELECT
                        xz_session_id,xz_uid
                    FROM
                        zk_member_login
                    GROUP BY
                        xz_session_id
                    ORDER BY
                        addTime DESC
                ) ml
            WHERE
                el.session_id = ml.xz_session_id
	    ) log
        LEFT JOIN zk_users ON log.xz_uid = zk_users.id
        ");*/

        return ['code' => 0, 'count' => $count, 'data' => $res, 'msg' => ''];
    }
}